﻿using System.Windows;
using BitsOfStuff.MyActions;

namespace BitsOfStuff
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class NewCharWindow : Window
    {
        private MyShapeRecognize _myShapeRecognize;
        private InkPadWindow parent;

        /// <summary>
        /// Constructor of window for pickyng char
        /// </summary>
        /// <param name="shapeRecognize">shape recognizer, that receve new char</param>
        /// <param name="inkPadWindow">inkPad for redrawing</param>
        public NewCharWindow(MyShapeRecognize shapeRecognize, InkPadWindow inkPadWindow)
            : this()
        {
            _myShapeRecognize = shapeRecognize;
            parent = inkPadWindow;
        }

        /// <summary>
        /// Parametrless consctructor of window
        /// </summary>
        public NewCharWindow()
        {
            this.InitializeComponent();

            // Insert code required on object creation below this point.
            addCharToDropBox();
        }

        /// <summary>
        /// function that inset posible chars to our method
        /// </summary>
        private void addCharToDropBox()
        {
            for (byte i = 48; i < 58; i++)
            {
                char c = System.Convert.ToChar(i);
                actionSelecter.Items.Add(c);
            }

            for (byte i = 65; i < 91; i++)
            {
                char c = System.Convert.ToChar(i);
                actionSelecter.Items.Add(c);
            }
            actionSelecter.Items.Add("Space");
            actionSelecter.Items.Add("New Line");
            actionSelecter.Items.Add("Shift");
            actionSelecter.Items.Add("Backspace");
            actionSelecter.Items.Add("!");
            actionSelecter.Items.Add("?");
            actionSelecter.Items.Add(".");
        }

        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            _myShapeRecognize.addOrRemoveAction(getAction());
            parent.clearStroke();
            this.Hide();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            this.Hide();
        }

        /// <summary>
        /// Function that return action that is stored in profile base of choosen char, convert string text to char values
        /// </summary>
        /// <returns>Myactions to store</returns>
        public MyShowAction getAction()
        {
            if (actionSelecter.SelectedItem is char)
            {
                return new MyShowAction((char)actionSelecter.SelectedItem, null);
            }
            else
            {
                var selectedValue = (string)actionSelecter.SelectedItem;
                switch (selectedValue)
                {
                    case "Space":
                        return new MyShowAction(' ', null);
                    case "New Line":
                        return new MyShowAction('\n', null);
                    case "Shift":
                        return new MyShowAction('↑', null);
                    case "Backspace":
                        return new MyShowAction('←', null);
                    case ".":
                        return new MyShowAction('.', null);
                    default:
                        return new MyShowAction(' ', null);
                }
            }
        }
    }
}